import GerikSpells
from GSGraphicsPolicies import GSPlot

from GSTargetInfoPolicies import GSSpecificUnitTarget

import GerikSpellsInterface

szColor = "COLOR_YELLOW"
fAlpha = 1.0

# Just a simple overridden GSPlot so I can make all the magic spells
# have the same Graphics Plot policy.

class CivcraftSpellPlotGraphicsPolicy(GSPlot):
    def __init__(self):
        GSPlot.__init__(self)
        GSPlot.setRangePlotColor(self, szColor, fAlpha)

    
# A target policy that works like the normal SpecificUnitTarget, but just
# changes how the bars look and the words that an invalid unit has in their info pane (why they're invalid).
class CivcraftSpecificUnitTargetPolicy(GSSpecificUnitTarget):
    def __init__(self, pTargettableCallback):
        GSSpecificUnitTarget.__init__(self, pTargettableCallback)
        self.m_pInvalidTargetDescriptionCallback = None

    def setInvalidTargetDescriptionCallback(self, pInvalidTargetDescriptionCallback):
        self.m_pInvalidTargetDescriptionCallback = pInvalidTargetDescriptionCallback

    def parseInfo(self, bStrategyOption):
        szText = GSSpecificUnitTarget.parseInfo(self, bStrategyOption)
        pCurrentSpell = GerikSpellsInterface.getCurrentSpell()
        if (not self.isTargettable(pCurrentSpell.getCastingGroup(), pCurrentSpell.getCastingPlot(), self.getTarget(), False) ):
            if self.m_pInvalidTargetDescriptionCallback:
                szText += self.m_pInvalidTargetDescriptionCallback(self.getTarget(), bStrategyOption)

        return szText
            
        

    def getBars(self):
        bShowHealth = False
        bShowShields = False
        bShowEnergy = False
        if (self.getTarget().isFighting()):
                bShowHealth = False
                bShowShields = False
                bShowEnergy = False
        else:
                bShowHealth = True
                bShowShields = self.getTarget().hasShields()
                bShowEnergy = self.getTarget().hasEnergy()

        pBars = []
        if bShowHealth:
            pBars.append( (self.getTarget().currHitPoints(), self.getTarget().maxHitPoints(), "COLOR_HIT_POINTS_TEXT") )

        if bShowShields:
            pBars.append( (self.getTarget().currShields(), self.getTarget().maxShields(), "COLOR_SHIELDS_TEXT") )

        if bShowEnergy:
            pBars.append( (self.getTarget().currEnergy(), self.getTarget().maxEnergy(), "COLOR_ENERGY_TEXT") )

        return pBars
